﻿using System.Collections.Generic;
using System.Data;
using System.Text;
using Utils;
using DataHelper;
namespace DAL
{
    //兼职信息
   public class EmpDutyDao
   {
       #region 兼职信息

      

        public bool DeleteOneInfo(string id)
        {
            return SQLHelper.ExecuteSqlWithTransaction("Delete from Admin_EmpOtherDuty Where  EimID=" + id);
        }

        public DataTable GetOneInfo(string id)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from View_EmpOtherDuty Where  EimID=" + id);
        }

        

        public string GetSQL(string serWord, string bTime, string eTime, string statu, string timeType)
        {
            StringBuilder strSQL = new StringBuilder("Select * From View_EmpOtherDuty Where 1=1 ");
            if (!string.IsNullOrWhiteSpace(serWord))
                strSQL.Append(" And (EmpCode='" + serWord + "' Or EmpName Like '%" + serWord + "%')");
            else
            {
                if (statu == "")
                    strSQL.Append(" and Statu ='Y' ");
                else
                {
                    if (statu != "A")
                        strSQL.Append(" and Statu ='" + statu + "' ");
                }
                switch (timeType)
                {
                    case "CheckTime":
                        if (RegexRule.IsDate(bTime))
                            strSQL.Append(" And CheckTime>='" + bTime + "'");
                        if (RegexRule.IsDate(eTime))
                            strSQL.Append(" And CheckTime<='" + eTime + "'");
                        break;
                    case "BeginTime":
                        if (RegexRule.IsDate(bTime))
                            strSQL.Append(" And BeginTime>='" + bTime + "'");
                        if (RegexRule.IsDate(eTime))
                            strSQL.Append(" And BeginTime<='" + eTime + "'");
                        break;
                    case "EndTime":
                        if (RegexRule.IsDate(bTime))
                            strSQL.Append(" And EndTime>='" + bTime + "'");
                        if (RegexRule.IsDate(eTime))
                            strSQL.Append(" And EndTime<='" + eTime + "'");
                        break;
                    case "InputTime":
                        if (RegexRule.IsDate(bTime))
                            strSQL.Append(" And InputTime>='" + bTime + "'");
                        if (RegexRule.IsDate(eTime))
                            strSQL.Append(" And InputTime<='" + eTime + "'");
                        break;
                }
            }
            strSQL.Append(" Order by EimID ASC");
            return strSQL.ToString();
        }
        public DataTable GetLists(string serWord, string bTime, string eTime, string statu, string timeType)
        {
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(GetSQL(serWord, bTime, eTime, statu, timeType));
            return dt;
        }
        public DataTable GetLists(string empCode)
        {
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt("Select * From View_EmpOtherDuty Where Statu ='Y' and  EmpCode='" + empCode + "' Order by EimID ASC");
            return dt;
        }
        #endregion
    }
}
